package tools;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TelCheckTools {//验证手机号是否有效
    static String YD = "^[1]{1}(([3]{1}[4-9]{1})|([5]{1}[012789]{1})|([8]{1}[12378]{1})|([4]{1}[7]{1}))[0-9]{8}$";
    static String LT = "^[1]{1}(([3]{1}[0-2]{1})|([5]{1}[56]{1})|([8]{1}[56]{1}))[0-9]{8}$";
    static String DX = "^[1]{1}(([3]{1}[3]{1})|([5]{1}[3]{1})|([8]{1}[09]{1}))[0-9]{8}$";

    //禁止初始化
    private TelCheckTools(){

    }
    //手机号码的有效性验证

    public static boolean isValidPhoneNumber(String number) {

        boolean flag = false;

        if (number.length() == 11 && (number.matches(YD) || number.matches(LT) || number.matches(DX))) {

            flag = true;

        }

        return flag;

    }



    //判断email地址是否有效

    public static boolean isEmail(String email) {

        String patternString = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";

        return isMatcher(patternString, email);

    }


    //是否是数字和字母

    public static boolean isMatchCharOrNumber(String str) {

        String patternString = "^[\\d|a-z|A-Z]+$";

        return isMatcher(patternString, str);

    }

    //是否匹配

    public static boolean isMatcher(String patternString, String str)

    {

        boolean isValid = false;

        CharSequence inputStr = str;

        Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);

        Matcher matcher = pattern.matcher(inputStr);

        if (matcher.matches()) {

            isValid = true;
        }
        return isValid;

    }
    
    
    public static void main(String arg[]){//main--来自高金磊
    
        System.out.println(isValidPhoneNumber("13839408809"));
    }

}

